(function () {


    async function sleep(ms) {
        return new Promise((s,r)=>{
            setTimeout(s,ms);
        });
    }




    let integral = function (userAccount,domainCode) {
        this.userAccount=userAccount;
        this.domainCode=domainCode;
        this.funcArray=null;
    };

    integral.prototype.time=1000;

    integral.prototype.initialParameters=function(){
        let r1 = /userAccount":"([0-9]*)"/;
        let r2 = /domainCode":"([0-9]*)"/;
        let s2 = decodeURIComponent(document.cookie ? document.cookie : "");
        this.userAccount = r1.exec(s2) ? r1.exec(s2)[1] : "";
        this.domainCode = r2.exec(s2) ? r2.exec(s2)[1] : "";
    };


    integral.prototype.delegate=function (str) {
        //console.log(str);
    };


    /**
     * 刷答题分的
     * @returns {Promise.<void>}
     */
    integral.prototype.ePoint=async function() {
        let parent = this;

        $.post("http://xf.faxuan.net/pss/service/postPoint?operateType=epoint" +
            "&userAccount=" + this.userAccount +
            "&domainCode=" + this.domainCode +
            "&"+"timestamp=" + new Date() +
            "&exerScore=60" +
            "&expointValue=20",
            () => parent.delegate("刷答题分的")
        ).fail((ex) => {
            if(ex.status&&ex.status>=500) parent.ePoint.call(parent);
        });
    };


    /**
     * 刷10分钟的
     * @returns {Promise.<void>}
     */
    integral.prototype.sPoint=async function() {
        let parent = this;

        $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=spoint" +
            "&userAccount=" + this.userAccount +
            "&domainCode=" + this.domainCode +
            "&"+"timestamp=" + new Date() +
            "&stime=88",
            () => parent.delegate("刷10分钟的")
        ).fail((ex) => {
            if(ex.status&&ex.status>=500) parent.sPoint();
        });
    };


    /**
     * 刷登录的
     * @returns {Promise.<void>}
     */
    integral.prototype.lPoint=async function() {
        let parent = this;

        $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=lpoint" +
            "&userAccount=" + this.userAccount +
            "&domainCode=" + this.domainCode +
            "&"+"timestamp=" + new Date(),
            () => parent.delegate("刷登录的")
        ).fail((ex) => {
            if(ex.status&&ex.status>=500) parent.lPoint();
        });
    };

    /**
     * 刷1分的
     * @returns {Promise.<void>}
     */
    integral.prototype.iPoint=async function() {
        let parent = this;
        $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=ipoint" +
            "&userAccount=" + this.userAccount +
            "&domainCode=" + this.domainCode +
            "&"+"timestamp=" + new Date(),
            () => parent.delegate("刷1分的")
        ).fail((ex) => {
            if(ex.status&&ex.status>=500) parent.iPoint();
        });
    };


    /**
     * 刷活动的
     * @returns {Promise.<void>}
     */
    integral.prototype.aPoint=async function() {
        let parent = this;
        $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=apoint" +
            "&userAccount=" + this.userAccount +
            "&domainCode=" + this.domainCode +
            "&"+"timestamp=" + new Date(),
            () => parent.delegate("刷1分的")
        ).fail((ex) => {
            if(ex.status&&ex.status>=500) parent.aPoint();
        });
    };


    integral.prototype.excutePoint=async function (functioncallback,count,sleepMS) {


        for(let i=0;i<count;i++) {
            await sleep(sleepMS);
            await functioncallback.apply(this);
        }
    };

    integral.prototype.excutePoint2=async function (functioncallback,count,sleepMS) {


        for(let i=0;i<count;i++) {
            await sleep(sleepMS);
            await functioncallback();
        }
    };

    integral.prototype.test=async function () {
        setTimeout(()=>console.log(this.a1),100);
    }

    integral.prototype.initialStart=async function () {
        this.initialParameters();
        await this.start();
    };


    integral.prototype.pointactiveFive=async function () {


        this.excutePoint(async ()=>{
            await sleep.call(this,this.time);
            await this.aPoint.call(this);
            console.log.call(this,this.userAccount+":活动-第"+(i+1)+"次\r\n");
        },5,this.time);
        console.log(this.userAccount+"完成带活动的");

    };

    integral.prototype.start=async function () {

        //一次1分的 +1
        let count=1;
        let i=0;
        await this.start2();

        //5次活动  +10
        count=5;
        for(i=0;i<count;i++){
            await sleep(this.time);
            await this.aPoint();
            console.log(this.userAccount+":活动-第"+(i+1)+"次\r\n");
        }

        console.log(this.userAccount+"完成带活动的");



    };


    integral.prototype.start2=async function () {

        //一次1分的 +1
        let count=1;
        let i=0;
        for(i=0;i<count;i++){
            await sleep(this.time);
            await this.iPoint();
            console.log(this.userAccount+":1分-第"+(i+1)+"次");
        }



        //两次登录  +10
        count=2;
        for(i=0;i<count;i++){
            await sleep(this.time);
            await this.lPoint();
            console.log( this.userAccount+":登录-第"+(i+1)+"次\r\n");
        }

        //两次刷分  +60
        count=3;
        for(i=0;i<count;i++){
            await sleep(this.time);
            await this.ePoint();
            console.log(this.userAccount+":测验-第"+(i+1)+"次\r\n");
        }

        //三次时间  +40
        count=2;
        for(i=0;i<count;i++){
            await sleep(this.time);
            await this.sPoint();
            console.log(this.userAccount+"时间-第"+(i+1)+"次\r\n");
        }

        console.log(this.userAccount+"不带活动结束")


    };


    function start() {

        //肖哥的
        //new integral("5329011660022","100008014001166").start2().then();

        //爸爸的
        new integral("5329260410018","100008014006041").start2();

        //我的
        new integral("5329011660024","100008014001166").start2();

        //王艳芳的
        //new integral("5329012270028","100008014001230").start().then();

        //陈老师的
        //new integral("5329011660015","100008014001166").start().then();

        //局长的
        //new integral("5329011660001","100008014001166").start2().then();

    }

    start();

})();

